// 封装eventEmitter 发布订阅 
// 定义EventEmitter 类 
var EventEmitter = /** @class */ (function () {
    function EventEmitter() {
        this.events = {}; //protected受保护的
    }
    // emit
    EventEmitter.prototype.emit = function (eventName) {
        var args = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            args[_i - 1] = arguments[_i];
        }
        if (!this.events[eventName])
            return false;
        this.events[eventName].forEach(function (listener) {
            return listener.apply(void 0, args);
        });
        return true;
    };
    // on
    EventEmitter.prototype.on = function (eventName, listener) {
        if (!this.events[eventName]) {
            this.events[eventName] = [listener];
        }
        else {
            this.events[eventName].push(listener);
        }
        return false;
    };
    // once
    EventEmitter.prototype.once = function (eventName, listener) {
        var on = function () {
            var args = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                args[_i] = arguments[_i];
            }
            return listener.apply(void 0, args);
        };
        on.fn = listener;
        this.on(eventName, on);
        return this;
    };
    return EventEmitter;
}());
var req = new EventEmitter();
req.once('data', function (data) {
    console.log(data);
});
req.emit('data', "123");
